layui.use(["layer","jquery"],function () {
    var
        layer = layui.layer,
        $ = layui.jquery;

    $.ajax({
        url:"/HomePage/getAllUsersRegistrationTime",
        data:{},
        type:'post',
        dataType:'json',
        success:function (data) {
            $("#todayUser").text(data.data.todayUser);
            $("#yesterdayUser").text(data.data.yesterdayUser);
            $("#monthUser").text(data.data.monthUser);
            $("#AllUsers").text(data.data.AllUsers);
        }
    });
    $("#refresh").click(function () {
        location.reload();
    });
    getTotalJinsiUser();
    function getTotalJinsiUser(){
        //查询进思用户人数
        $.ajax({
            url:"/HomePage/getTotalJinsiUser",
            data:{},
            type:'post',
            dataType:"json",
            success:function (data) {
                //查询进思用户人数
                $(".TotalJinsiUser").text(data.data);
                getTotalWebUser();
            }
        })
    }

    function getTotalWebUser(){
        //查询前端用户人数
        $.ajax({
            url:"/HomePage/getTotalWebUser",
            data:{"status":4},
            type:'post',
            dataType:"json",
            success:function (data) {
                //查询前端用户人数
                $("#TotalWebUser").text(data.data);
                var TotalJinsiUser = $("#TotalJinsiUser").text();
                $(".TotalNotJinsiUser").text(JSON.parse(data.data) - JSON.parse(TotalJinsiUser));


            }
        })
    }
    getTotalBackstageUser();
    function getTotalBackstageUser(){
        //查询后端端用户人数
        $.ajax({
            url:"/HomePage/getTotalBackstageUser",
            data:{"status":2},
            type:'post',
            dataType:"json",
            success:function (data) {
                //查询后端端用户人数
                $("#TotalBackstageUser").text(data.data);
            }
        })
    }
    getCreatorExmaine();
    function getCreatorExmaine(){
        //查询创作者待认证信息
        $.ajax({
            url:"/HomePage/getCreatorExmaine",
            data:{"result":1},
            type:'post',
            dataType:"json",
            success:function (data) {
                //查询创作者待认证信息
                $("#CreatorExmaine").text(data.data);
            }
        })
    }
    //待审核跳转
    $("#pendingTransactionTextchuangzuozhe").click(function () {
        if ($("#pendingTransactionTextchuangzuozhe").text() == "创作者认证待处理信息"){
            parent.tabParentChange(81);
        }
    });
    //快捷入口跳转
    $("#account_settings").click(function () {
        if ($("#account_settings").text() == "用户设置"){
            parent.tabParentChange(4);
        }
    });
    $("#user_list").click(function () {
        if ($("#user_list").text() == "用户列表"){
            parent.tabParentChange(74);
        }
    });
    $("#jinsi_user").click(function () {
        if ($("#jinsi_user").text() == "进思用户"){
            parent.tabParentChange(75);
        }
    });
    $("#not_jinsi_user").click(function () {
        if ($("#not_jinsi_user").text() == "非进思用户"){
            parent.tabParentChange(76);
        }
    });
    $("#zero_consumption_user").click(function () {
        if ($("#zero_consumption_user").text() == "零消费用户"){
            parent.tabParentChange(98);
        }
    });
    $("#creator_application").click(function () {
        if ($("#creator_application").text() == "创作者申请"){
            parent.tabParentChange(81);
        }
    });
    $("#feedback_list").click(function () {
        if ($("#feedback_list").text() == "反馈列表"){
            parent.tabParentChange(96);
        }
    });
    $("#personnel_statistics_chart").click(function () {
        if ($("#personnel_statistics_chart").text() == "人员统计图"){
            parent.tabParentChange(69);
        }
    });




    UserStatistics();
    //用户统计
    function UserStatistics(){
        $.ajax({
            url:"/HomePage/getAllUserCreateDate",
            data:{},
            type:'post',
            dataType:'json',
            success:function (data) {
                $("#WeekCourseBox").css("display","none");
                $("#WeekProductBox").css("display","none");
                $("#WeekUserBox").show();
                list = [];
                list.push(data.data.yi);
                list.push(data.data.er);
                list.push(data.data.san);
                list.push(data.data.si);
                list.push(data.data.wu);
                list.push(data.data.liu);
                list.push(data.data.qi);
                UserWeek(list);
            }
        });
        //获取本周与上周课程数量
        $.ajax({
            url:"/HomePage/TotalOfThisWeekAndLastWeekUserCreateDate",
            data:{},
            type:'post',
            dataType:'json',
            success:function (data) {
                var thisWeek = data.data.thisWeek;
                $("#ThisWeekUser").text(thisWeek);
                var lastWeek = data.data.lastWeek;
                $("#LastWeekUser").text(lastWeek);
                var a = Number(thisWeek)/Number(lastWeek);
                if(Number(thisWeek)==0 && Number(lastWeek)!=0){
                    a =Number(lastWeek) *100+"%";
                    $("#WeekUserQuantity").text("-"+a);
                }
                if (Number(thisWeek)!=0 && Number(lastWeek)==0) {
                    a =Number(thisWeek) *100+"%";
                    $("#WeekUserQuantity").text(a);
                    $("#WeekUserQuantity").css("color","red");
                }
                if (Number(thisWeek)==Number(lastWeek)){

                    $("#WeekUserQuantity").text("0%");
                    $("#WeekUserQuantity").css("color","red");
                }else if(a>=1){
                    a =a *100+"%";
                    $("#WeekCourseQuantity").text(a);
                    $("#WeekCourseQuantity").css("color","red");
                }else if(a<1){
                    a =(a-1) *100+"%";
                    $("#WeekUserQuantity").text("-"+a);
                }
            }
        });
    }
    function UserWeek(data){
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            xAxis: {
                type: 'category',
                data: ['星期一', '星期二', '星期三', '星期四','星期五','星期六','星期日']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    data:data,
                    type: 'line'
                }
            ]
        };

        option && myChart.setOption(option);
    }

})